from django.db import models
from accounts.models import User

class Image(models.Model):
    IMAGE_TYPE_CHOICES = (
        ('avatar', '头像'),
        ('id_card', '身份证'),
        ('certification', '资格证书'),
        ('service', '服务图片'),
        ('review', '评价图片'),
        ('other', '其他'),
    )
    
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='images', verbose_name='用户')
    image_type = models.CharField(max_length=20, choices=IMAGE_TYPE_CHOICES, verbose_name='图片类型')
    image = models.ImageField(upload_to='images/%Y/%m/%d/', verbose_name='图片文件')
    description = models.CharField(max_length=200, blank=True, verbose_name='描述')
    
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_at = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    
    class Meta:
        db_table = 'image'
        verbose_name = '图片'
        verbose_name_plural = verbose_name
        ordering = ['-created_at']
    
    def __str__(self):
        return f"{self.user.username}的{self.get_image_type_display()}图片"